// pkg/router/router.go
package demo

import (
	"sync"
)

type HandlerFunc func(interface{})

type Router struct {
	handlers sync.Map // map[uint32]HandlerFunc
}

func NewRouter() *Router {
	return &Router{}
}

func (r *Router) Register(protocolID uint32, handler HandlerFunc) {
	r.handlers.Store(protocolID, handler)
}

func (r *Router) GetHandler(protocolID uint32) (HandlerFunc, bool) {
	val, ok := r.handlers.Load(protocolID)
	if !ok {
		return nil, false
	}
	return val.(HandlerFunc), true
}
